package com.jdk.learn.thread;

import java.util.concurrent.CountDownLatch;

/**
 * 计数器  在次数达到后开始执行主线程任务
 */
public class MultiThreadCountDownLatch {
    public static void main(String[] args) {
        CountDownLatch count = new CountDownLatch(2);
        new Thread(() -> {
            System.out.println("子线程执行");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            count.countDown();
        }).start();
        new Thread(() -> {
            System.out.println("子线程2执行");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            count.countDown();
        }).start();
        try {
            count.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("父线程执行");
    }
}
